<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/crm/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/crm/css/public.css" media="all">
    <link rel="stylesheet" href="/static/crm/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        .layui-table th {
            font-weight: bold;
            color: #333333;
            text-align: center;
        }

        .layui-table {
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <fieldset class="table-search-fieldset" style="display: none;">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">课程名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">价格</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="price" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">单位</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="unit" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">校区</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="campus_id" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">专业</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="major_id" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" style="background-color: #393D49;" lay-event="refresh"><i class="fa fa-refresh layui-anim-rotate"></i></button>
                </div>
            </script>

            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        
            <script type="text/html" id="currentTableBar">
    <a class="layui-btn  layui-btn-danger layui-btn-sm " lay-event="add" ><i class="layui-icon  layui-icon-edit layui-icon-addition"></i>添加</a>
            </script>

        </div>
    </div>
    <script src="/static/crm/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form', 'table', 'jquery', 'layer'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                table = layui.table;

            table.render({
                elem: '#currentTableId',
                url: '/crm/contract.contract/commodity',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '搜索',
                    layEvent: 'search',
                    icon: 'layui-icon-search'
                }],
                cols: [[
                    { field: 'id', width: 60, title: 'ID', sort: true },
                    { field: 'name', title: '课程名称' },
                    { field: 'price', title: '价格', width: 130, sort: true },
                    { field: 'unit_name', width: 60, title: '单位' },
                    { field: 'minute_hour', width: 90, title: '课时/分钟' }, // 一对多数据
                    { field: 'major', templet:function(d){return d.major.name}, title: '专业' },
                    { field: 'campus', templet:function(d){return d.campus.name}, title: '校区' },
                    { title: '操作', minWidth: 80,  width: 90, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
                ]],
                // skin: 'row'
            });

            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                table.reload('currentTableId', {
                    page: { curr: 1 },
                    where: data.field
                }, 'data');
                return false;
            });
        // table.on('edit(currentTableFilter)', function (obj) {
        //     if (layui.table.getData('currentTableId').length > 0) {
        //         for (var i in layui.table.getData('currentTableId')) {
        //             console.log( $(".layui-table-box tbody tr[data-index='" + i + "'] td[data-field='zonga'] .layui-table-cell").text());
        //         }
        //     }
           
        //     var value  = obj.value;  
        //     console.log(obj);
        //     data = obj.data
        //     fi = obj.field
        // });
    });

</script>